package com.cx.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.cx.filter.H5Filter;
import com.cx.interceptor.AdminInterceptor;
import com.cx.interceptor.H5Interceptor;

@Configuration
public class WebConfig implements WebMvcConfigurer {

	@Bean
	public H5Interceptor getH5Interceptor(){
		return new H5Interceptor();
	}
	
	@Bean
	public AdminInterceptor getAdminInterceptor(){
		return new AdminInterceptor();
	}
	
	@Bean
	public H5Filter getH5Filter(){
		return new H5Filter();
	}
	
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getH5Interceptor()).addPathPatterns("/h5/**");
        registry.addInterceptor(getAdminInterceptor()).addPathPatterns("/admin/**"); 
    }
    
    /**
     * 添加拦截器
     * */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Bean
    public FilterRegistrationBean filterRegist() {
        FilterRegistrationBean frBean = new FilterRegistrationBean();
        frBean.setFilter(getH5Filter());
        frBean.addUrlPatterns("/*");
        return frBean;
    }
    
}
